package com.drophair.jspwork.Servlet;

import com.drophair.jspwork.bean.Active;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "ActiveCodeServlet", value = "/ActiveCodeServlet")
public class ActiveCodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        String m_code="";
        m_code=request.getParameter("m_code");
        Active active=new Active();
        active.setCode(m_code);
        Cookie cookie;
        try {
            String a_code=active.getCode();
            cookie=new Cookie("a_code",a_code);
            System.out.println(a_code);
            response.addCookie(cookie);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        response.sendRedirect("/common/activecode.jsp");
    }
}
